<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&#x00A0;">
]>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:umbraco.library="urn:umbraco.library"
  xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon"
  xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"
  xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath"
  xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions"
  xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
  xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
  xmlns:CWS.Twitter="urn:CWS.Twitter"
  xmlns:georss="http://www.georss.org/georss"
  exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets CWS.Twitter georss">


  <xsl:output method="xml" omit-xml-declaration="yes"/>

  <xsl:param name="currentPage"/>

  <!--
    Twitter for Umbraco
    Version:  1.6    
    Author:   Warren Buckley
    Site:     www.creativewebspecialist.co.uk
    Twitter:  @warrenbuckley
  -->
  
  <!-- Twitter username -->
  <xsl:param name="twitterUsername" select="/macro/twitterUsername" />

  <!-- Number of Statuses -->
  <xsl:param name="noStatus">
    <xsl:choose>
      <!-- Max status's we can retrieve is upto 200 -->
      <xsl:when test="/macro/noStatus &lt;= 200">
        <xsl:value-of select="/macro/noStatus"/>
      </xsl:when>
      <xsl:otherwise>
        200
      </xsl:otherwise>
    </xsl:choose>
  </xsl:param>

  <!-- Display @replies? -->
  <xsl:param name="displayReplies" select="/macro/displayReplies" />

  <!-- Display native RTs? -->
  <xsl:param name="displayNativeRTs">
    <xsl:choose>
      <xsl:when test="/macro/displayNativeRTs = 1">
        <xsl:text>true</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>false</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:param>

  <!-- Display map? -->
  <xsl:param name="displayMaps" select="/macro/displayMaps" />

  <!-- Goole Static Maps Params-->
  <xsl:param name="baseURL"  select="'http://maps.google.com/maps/api/staticmap'"/>
  <!-- DO NOT CHANGE URL -->
  <xsl:param name="zoom"     select="/macro/zoom" />
  <!-- Zoom level (0 to 21) -->
  <xsl:param name="size"     select="/macro/size" />
  <!-- Size of Map in pixels (400x400) -->
  <xsl:param name="mapType"  select="/macro/mapType" />
  <!-- Map Type (roadmap, satellite, terrain, hybrid) -->


  <xsl:template match="/">

    <!-- Twitter XML URL -->
    <xsl:variable name="twitterXMLUrl" select="concat(' http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=', $twitterUsername ,'&amp;include_rts=', $displayNativeRTs ,'&amp;count=200')"/>

    <!-- Go fetch the tweets -->
    <xsl:choose>
      <xsl:when test="$displayReplies = 1">
        <!-- Just show user's tweets only and display @replies -->
        <xsl:for-each select="umbraco.library:GetXmlDocumentByUrl($twitterXMLUrl)//statuses/status">
          <!-- Check that we only show the number of tweets we want -->
          <xsl:if test="position() &lt;= $noStatus">
            <xsl:apply-templates mode="tweet" select="current()"/>
          </xsl:if>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="$displayReplies = 0">
        <!-- Just show user's tweets only and DONT display @replies -->
        <xsl:for-each select="umbraco.library:GetXmlDocumentByUrl($twitterXMLUrl)//statuses/status [in_reply_to_screen_name = '']">
          <!-- Check that we only show the number of tweets we want -->
          <xsl:if test="position() &lt;= $noStatus">
            <xsl:apply-templates mode="tweet" select="current()"/>
          </xsl:if>
        </xsl:for-each>
      </xsl:when>
    </xsl:choose>

  </xsl:template>

  <xsl:template match="status" mode="tweet">
    <!-- Change the XHTML here for how you want each tweet to be displayed -->

    <div class="tweet">
      <p>
        <!-- Your Profile Image -->
        <img src="{user/profile_image_url}" />

        <!-- Your real name (not profile name) -->
        <strong>
          <xsl:value-of select="user/name"/>
        </strong>
        -
        <!-- Date of tweet -->
        <span>
          <xsl:value-of select="umbraco.library:FormatDateTime(CWS.Twitter:FormatTwitterDate(created_at), 'ddd d MMM yy @ H:mm')"/>
        </span>

        <!-- Tweet content-->
        <xsl:value-of select="CWS.Twitter:FormatUrls(text)" disable-output-escaping="yes"/>
      </p>

      <!-- Show Map of Tweet - IF value in XML is there & user enabled maps -->
      <xsl:if test="geo/georss:point != '' and $displayMaps = 1">
        <p>
          <!-- Pass coordinates to map template-->
          <xsl:call-template name="map">
            <!-- Google wants coordinates as comma seperated so replace (space) with comma -->
            <xsl:with-param name="coordinates" select="umbraco.library:Replace(geo/georss:point,' ',',')" />
          </xsl:call-template>
        </p>
      </xsl:if>
    </div>

    <!-- EXAMPLE GEO TWEET/STATUS XML (Use any information you want/need, just tweak the XSLT) -->
    <!--
    <status>
      <created_at>Wed Aug 25 19:40:45 +0000 2010</created_at>
      <id>22113974549</id>
      <text>Sending out a geo tagged tweet as a test to update the twitter for #umbraco package to the new API from twitter</text>
      <source>&lt;a href=&quot;http://twitter.com/&quot; rel=&quot;nofollow&quot;&gt;Twitter for iPhone&lt;/a&gt;</source>

      <truncated>false</truncated>
      <in_reply_to_status_id></in_reply_to_status_id>
      <in_reply_to_user_id></in_reply_to_user_id>
      <favorited>false</favorited>
      <in_reply_to_screen_name></in_reply_to_screen_name>
      <retweet_count></retweet_count>
      <retweeted>false</retweeted>

      <user>
        <id>9751992</id>
        <name>Warren Buckley</name>
        <screen_name>warrenbuckley</screen_name>
        <location>iPhone: 51.559616,0.592538</location>
        <description>A web developer who is based in the UK that works for Norwegian Web Agency Xeed - http://www.xeed.no</description>

        <profile_image_url>http://a3.twimg.com/profile_images/696762619/warren-buckley_normal.jpg</profile_image_url>
        <url>http://www.creativewebspecialist.co.uk</url>
        <protected>false</protected>
        <followers_count>557</followers_count>
        <profile_background_color>022330</profile_background_color>
        <profile_text_color>333333</profile_text_color>

        <profile_link_color>0084B4</profile_link_color>
        <profile_sidebar_fill_color>C0DFEC</profile_sidebar_fill_color>
        <profile_sidebar_border_color>a8c7f7</profile_sidebar_border_color>
        <friends_count>257</friends_count>
        <created_at>Sun Oct 28 11:44:59 +0000 2007</created_at>
        <favourites_count>974</favourites_count>

        <utc_offset>0</utc_offset>
        <time_zone>London</time_zone>
        <profile_background_image_url>http://s.twimg.com/a/1282351897/images/themes/theme15/bg.png</profile_background_image_url>
        <profile_background_tile>false</profile_background_tile>
        <profile_use_background_image>true</profile_use_background_image>
        <notifications>false</notifications>

        <geo_enabled>true</geo_enabled>
        <verified>false</verified>
        <following>true</following>
        <statuses_count>7772</statuses_count>
        <lang>en</lang>
        <contributors_enabled>false</contributors_enabled>

        <follow_request_sent>false</follow_request_sent>
        <listed_count>55</listed_count>
        <show_all_inline_media>false</show_all_inline_media>
      </user>
      <geo xmlns:georss="http://www.georss.org/georss">
        <georss:point>51.5596798 0.59269702</georss:point>
      </geo>

      <coordinates xmlns:georss="http://www.georss.org/georss">
        <georss:point>51.5596798 0.59269702</georss:point>
      </coordinates>
      <place xmlns:georss="http://www.georss.org/georss">
        <id>433a0c1e74bddb9e</id>
        <name>Castle Point</name>
        <full_name>Castle Point, Essex</full_name>

        <place_type>city</place_type>
        <url>http://api.twitter.com/1/geo/id/433a0c1e74bddb9e.json</url>
        <attributes/>
        <bounding_box>
          <georss:polygon>51.500769 0.5157113 51.500769 0.703401 51.5877718 0.703401 51.5877718 0.5157113</georss:polygon>
        </bounding_box>
        <country code="">United Kingdom</country>

      </place>
      <contributors/>
    </status>
    -->


    <!-- EXAMPLE RETWEETED TWEET/STATUS XML (Use any information you want/need, just tweak the XSLT) -->
    <!--
    <status>
      <created_at>Wed Aug 25 19:20:30 +0000 2010</created_at>
      <id>22112745181</id>
      <text>RT @leekelleher: Any #umbraco devs want to help on an ELMAH package? Need help with package action, (not enough hours in the day!) http: ...</text>
      <source>&lt;a href=&quot;http://www.tweetdeck.com&quot; rel=&quot;nofollow&quot;&gt;TweetDeck&lt;/a&gt;</source>

      <truncated>true</truncated>
      <in_reply_to_status_id></in_reply_to_status_id>
      <in_reply_to_user_id></in_reply_to_user_id>
      <favorited>false</favorited>
      <in_reply_to_screen_name></in_reply_to_screen_name>
      <retweet_count></retweet_count>
      <retweeted>false</retweeted>

      <retweeted_status>
        <created_at>Wed Aug 25 17:16:13 +0000 2010</created_at>
        <id>22105108358</id>
        <text>Any #umbraco devs want to help on an ELMAH package? Need help with package action, (not enough hours in the day!) http://bit.ly/9nu4G0</text>
        <source>&lt;a href=&quot;http://www.twhirl.org&quot; rel=&quot;nofollow&quot;&gt;Seesmic twhirl&lt;/a&gt;</source>

        <truncated>false</truncated>
        <in_reply_to_status_id></in_reply_to_status_id>
        <in_reply_to_user_id></in_reply_to_user_id>
        <favorited>false</favorited>
        <in_reply_to_screen_name></in_reply_to_screen_name>
        <retweet_count></retweet_count>
        <retweeted>false</retweeted>

        <user>
          <id>1005461</id>
          <name>Lee Kelleher</name>
          <screen_name>leekelleher</screen_name>
          <location>Yatton, Bristol, UK</location>
          <description>Umbraco MVP 2010 and ASP.NET developer.</description>

          <profile_image_url>http://a2.twimg.com/profile_images/56197478/northbynorthwest_300x300_normal.jpg</profile_image_url>
          <url>http://leekelleher.com/</url>
          <protected>false</protected>
          <followers_count>306</followers_count>
          <profile_background_color>709397</profile_background_color>
          <profile_text_color>333333</profile_text_color>

          <profile_link_color>1F98C7</profile_link_color>
          <profile_sidebar_fill_color>A0C5C7</profile_sidebar_fill_color>
          <profile_sidebar_border_color>86A4A6</profile_sidebar_border_color>
          <friends_count>184</friends_count>
          <created_at>Mon Mar 12 12:29:59 +0000 2007</created_at>
          <favourites_count>2</favourites_count>

          <utc_offset>0</utc_offset>
          <time_zone>London</time_zone>
          <profile_background_image_url>http://a3.twimg.com/profile_background_images/88106321/shark.jpg</profile_background_image_url>
          <profile_background_tile>true</profile_background_tile>
          <profile_use_background_image>true</profile_use_background_image>
          <notifications>false</notifications>

          <geo_enabled>true</geo_enabled>
          <verified>false</verified>
          <following>false</following>
          <statuses_count>2735</statuses_count>
          <lang>en</lang>
          <contributors_enabled>false</contributors_enabled>

          <follow_request_sent>false</follow_request_sent>
          <listed_count>50</listed_count>
          <show_all_inline_media>false</show_all_inline_media>
        </user>
        <geo/>
        <coordinates/>
        <place/>

        <contributors/>
      </retweeted_status>
      <user>
        <id>9751992</id>
        <name>Warren Buckley</name>
        <screen_name>warrenbuckley</screen_name>
        <location>iPhone: 51.559616,0.592538</location>

        <description>A web developer who is based in the UK that works for Norwegian Web Agency Xeed - http://www.xeed.no</description>
        <profile_image_url>http://a3.twimg.com/profile_images/696762619/warren-buckley_normal.jpg</profile_image_url>
        <url>http://www.creativewebspecialist.co.uk</url>
        <protected>false</protected>
        <followers_count>557</followers_count>
        <profile_background_color>022330</profile_background_color>

        <profile_text_color>333333</profile_text_color>
        <profile_link_color>0084B4</profile_link_color>
        <profile_sidebar_fill_color>C0DFEC</profile_sidebar_fill_color>
        <profile_sidebar_border_color>a8c7f7</profile_sidebar_border_color>
        <friends_count>257</friends_count>
        <created_at>Sun Oct 28 11:44:59 +0000 2007</created_at>

        <favourites_count>974</favourites_count>
        <utc_offset>0</utc_offset>
        <time_zone>London</time_zone>
        <profile_background_image_url>http://s.twimg.com/a/1282351897/images/themes/theme15/bg.png</profile_background_image_url>
        <profile_background_tile>false</profile_background_tile>
        <profile_use_background_image>true</profile_use_background_image>

        <notifications>false</notifications>
        <geo_enabled>true</geo_enabled>
        <verified>false</verified>
        <following>true</following>
        <statuses_count>7771</statuses_count>
        <lang>en</lang>

        <contributors_enabled>false</contributors_enabled>
        <follow_request_sent>false</follow_request_sent>
        <listed_count>55</listed_count>
        <show_all_inline_media>false</show_all_inline_media>
      </user>
      <geo/>
      <coordinates/>

      <place/>
      <contributors/>
    </status>
    -->
  </xsl:template>

  <xsl:template name="map">
    <xsl:param name="coordinates" />

    <!--
    See Google Static Maps API to customise your map
    http://code.google.com/apis/maps/documentation/staticmaps/
    -->
    <img src="{$baseURL}?center={$coordinates}&amp;zoom={$zoom}&amp;size={$size}&amp;maptype={$mapType}&amp;markers=color:red|label:A|{$coordinates}&amp;sensor=false" />

  </xsl:template>

</xsl:stylesheet>